name: Daily Tag Creator
on:
schedule:
- cron: '00 18 * * *'
jobs:
create-daily-tag:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Date Command
run: sudo apt-get install -y tzdata
- name: Get the current date in IST
id: date
run: |
DATE=$(TZ='Asia/Kolkata' date +'%d-%m-%Y') || { echo "Failed to get date"; exit 1; }
echo "Current date in IST: $DATE"
echo "DATE=$DATE" >> $GITHUB_ENV
continue-on-error: false
- name: Check for commits today
id: commits
run: |
COMMITS=$(git log --since=midnight --until=now --oneline || { echo "Failed to check commits"; exit 1; })
echo "Commits today: $COMMITS"
if [ -z "$COMMITS" ]; then
echo "No commits found today"
echo "HAS_COMMITS=false" >> $GITHUB_ENV
else
echo "Commits found"
echo "HAS_COMMITS=true" >> $GITHUB_ENV
fi
continue-on-error: false
- name: Create Tag
if: env.HAS_COMMITS == 'true'
env:
TAG_DATE: ${{ env.DATE }}
run: |
echo "Creating tag $TAG_DATE"
git config --global user.name "github-actions[bot]" || { echo "Failed to configure git user name"; exit 1; }
git config --global user.email "github-actions[bot]@users.noreply.github.com" || { echo "Failed to configure git user email"; exit 1; }
git tag $TAG_DATE || { echo "Failed to create tag"; exit 1; }
git push origin $TAG_DATE || { echo "Failed to push tag"; exit 1; }
continue-on-error: false
- name: Log success message
if: success()
run: echo "Workflow completed successfully"
- name: Log failure message
if: failure()
run: echo "Workflow failed"